package com.github.baichuan.web.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
    private boolean success;
    private String message;
    private T data;

    public Result(){}

    public Result(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public static Result success(String message){
        return new Result(true, message);
    }

    public static <T> Result success(String message, @NonNull T data){
        Result result = new Result(true, message);
        result.data = data;
        return result;
    }

    public static Result fail(String message){
        return new Result(false, message);
    }

    public static Result fail(String message, @NonNull Object data){
        Result result = new Result(false, message);
        result.data = data;
        return result;
    }
}
